<?php
/**
* File that sets view of edit buslines page.
* @package busmap
*/
?>
<?php if(count($this->entries)){ ?>
	<h3>Bussiliinid: </h3>
	<table class="data-listing">
		<tr>
			<th>Nimi</th>
			<th class="big">Kirjeldus</th>
			<th>Läbib peatusi</th>
			<th class="button">Tegevused</th>
		</tr>
		<tr>
			<td colspan="5" id="busLinesFormContainer">
				<?php foreach ($this->entries as $key => $entry): ?>
				<?php
				$this->buslineForm = new Application_Form_Admin_editBusline();
				$entry->addTime = 'Lisatud: '.date('d.m.Y', $entry->addTime);
				$entry->nrStops = 'Peatusi: '.count($entry->busstops);
				$this->buslineForm->populate($entry->toArray());
				$this->buslineForm->populateWithBusstops($entry->busstops, $entry->id);
				$errorsTxt = '';
				if(array_key_exists('id', $_POST) && $_POST['id'] == $entry->id){
					if(count($this->errors)){
						foreach($this->errors as $error){
							$this->buslineForm->addErrorMessage($error);
							$this->buslineForm->populate($_POST);
							$errorsTxt .= '<div class="withErrors">'.array_pop($error).'</div>';
						}
					}
					if(array_key_exists('delete', $_POST)){
						$this->buslineForm->askDeleteConfirmation();
					}
				}
				echo ($errorsTxt)?$errorsTxt:'';
				$this->buslineForm->colorMeOnce();
				echo $this->buslineForm;
				?>
				<div style="clear:both;"></div>
				<?php endforeach ?>
				<script type="text/javascript">
					colorMeOnce($("#busLinesFormContainer"));
				</script>
			</td>
		</tr>
	</table>
	<div id="buslinesSelect" class="busstop-listing-popup">
		<div id="buslinesSelect-content"></div>
		<div id="buslinesSelect-counter" class="buslineSelect-counter"></div>
		<div class="buslinesSelect-close-button">
			<input type="button" class="red-button" onClick="hideBusstopListing()" value="Sulge">
		</div>
	</div>

<?php }else{ ?>
	Hetkel bussiliinid puuduvad andmebaasis.
<?php } ?>
<h4>Lisa uus bussiliin</h4>

<?php if($this->insertBuslineForm){ ?>
	<div id="buslinesNewContainer">
		<?php echo $this->render('admin/new-busline.phtml') ?>
		<div style="clear:both;"></div>
	</div>
<?php }else{ ?>
	<div id="buslinesNewButton" class="data-listing">
		<input type="button" value="Lisa bussiliin" class="submit-data" onClick="addNewBuslineShow()">
	</div>
	<div id="buslinesNewContainer"></div>
<?php } ?>